from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-19 14:02:44.351774
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 19, Dec, 2022
Time: 14:02:50
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.2544
Nobs: 875.000 HQIC: -51.5576
Log likelihood: 11554.5 FPE: 3.36689e-23
AIC: -51.7455 Det(Omega_mle): 3.03957e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296487 0.049734 5.961 0.000
L1.Burgenland 0.105523 0.034035 3.100 0.002
L1.Kärnten -0.106833 0.018277 -5.845 0.000
L1.Niederösterreich 0.214481 0.071418 3.003 0.003
L1.Oberösterreich 0.086335 0.067653 1.276 0.202
L1.Salzburg 0.249920 0.036140 6.915 0.000
L1.Steiermark 0.030369 0.047469 0.640 0.522
L1.Tirol 0.127492 0.038634 3.300 0.001
L1.Vorarlberg -0.061865 0.033213 -1.863 0.063
L1.Wien 0.062298 0.060384 1.032 0.302
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063703 0.102276 0.623 0.533
L1.Burgenland -0.009822 0.069991 -0.140 0.888
L1.Kärnten 0.049252 0.037587 1.310 0.190
L1.Niederösterreich -0.173104 0.146868 -1.179 0.239
L1.Oberösterreich 0.361773 0.139126 2.600 0.009
L1.Salzburg 0.286057 0.074320 3.849 0.000
L1.Steiermark 0.108805 0.097618 1.115 0.265
L1.Tirol 0.319225 0.079449 4.018 0.000
L1.Vorarlberg 0.024713 0.068302 0.362 0.717
L1.Wien -0.024686 0.124177 -0.199 0.842
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199862 0.025770 7.756 0.000
L1.Burgenland 0.090123 0.017635 5.110 0.000
L1.Kärnten -0.009154 0.009470 -0.967 0.334
L1.Niederösterreich 0.267523 0.037005 7.229 0.000
L1.Oberösterreich 0.112135 0.035055 3.199 0.001
L1.Salzburg 0.052833 0.018726 2.821 0.005
L1.Steiermark 0.015940 0.024596 0.648 0.517
L1.Tirol 0.102259 0.020018 5.108 0.000
L1.Vorarlberg 0.056754 0.017210 3.298 0.001
L1.Wien 0.112755 0.031288 3.604 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104305 0.026470 3.940 0.000
L1.Burgenland 0.047651 0.018114 2.631 0.009
L1.Kärnten -0.016984 0.009728 -1.746 0.081
L1.Niederösterreich 0.197322 0.038011 5.191 0.000
L1.Oberösterreich 0.277394 0.036007 7.704 0.000
L1.Salzburg 0.117782 0.019235 6.123 0.000
L1.Steiermark 0.100503 0.025264 3.978 0.000
L1.Tirol 0.126821 0.020562 6.168 0.000
L1.Vorarlberg 0.069900 0.017677 3.954 0.000
L1.Wien -0.025519 0.032138 -0.794 0.427
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131709 0.047753 2.758 0.006
L1.Burgenland -0.053984 0.032679 -1.652 0.099
L1.Kärnten -0.037048 0.017549 -2.111 0.035
L1.Niederösterreich 0.166618 0.068572 2.430 0.015
L1.Oberösterreich 0.132004 0.064958 2.032 0.042
L1.Salzburg 0.290932 0.034700 8.384 0.000
L1.Steiermark 0.034721 0.045577 0.762 0.446
L1.Tirol 0.161778 0.037095 4.361 0.000
L1.Vorarlberg 0.108163 0.031890 3.392 0.001
L1.Wien 0.066699 0.057978 1.150 0.250
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060438 0.037842 1.597 0.110
L1.Burgenland 0.038352 0.025897 1.481 0.139
L1.Kärnten 0.049904 0.013907 3.588 0.000
L1.Niederösterreich 0.227651 0.054341 4.189 0.000
L1.Oberösterreich 0.269814 0.051477 5.241 0.000
L1.Salzburg 0.059004 0.027498 2.146 0.032
L1.Steiermark -0.006735 0.036118 -0.186 0.852
L1.Tirol 0.157457 0.029396 5.356 0.000
L1.Vorarlberg 0.069270 0.025272 2.741 0.006
L1.Wien 0.075490 0.045945 1.643 0.100
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186134 0.045402 4.100 0.000
L1.Burgenland 0.018461 0.031070 0.594 0.552
L1.Kärnten -0.060336 0.016685 -3.616 0.000
L1.Niederösterreich -0.093993 0.065197 -1.442 0.149
L1.Oberösterreich 0.173904 0.061760 2.816 0.005
L1.Salzburg 0.061123 0.032992 1.853 0.064
L1.Steiermark 0.230248 0.043334 5.313 0.000
L1.Tirol 0.488793 0.035269 13.859 0.000
L1.Vorarlberg 0.051135 0.030320 1.686 0.092
L1.Wien -0.053678 0.055124 -0.974 0.330
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158499 0.051521 3.076 0.002
L1.Burgenland 0.000071 0.035257 0.002 0.998
L1.Kärnten 0.066425 0.018934 3.508 0.000
L1.Niederösterreich 0.201173 0.073983 2.719 0.007
L1.Oberösterreich -0.070990 0.070083 -1.013 0.311
L1.Salzburg 0.220471 0.037438 5.889 0.000
L1.Steiermark 0.112783 0.049174 2.294 0.022
L1.Tirol 0.084492 0.040022 2.111 0.035
L1.Vorarlberg 0.123695 0.034407 3.595 0.000
L1.Wien 0.105094 0.062553 1.680 0.093
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358263 0.030449 11.766 0.000
L1.Burgenland 0.006889 0.020837 0.331 0.741
L1.Kärnten -0.025457 0.011190 -2.275 0.023
L1.Niederösterreich 0.230431 0.043724 5.270 0.000
L1.Oberösterreich 0.156172 0.041419 3.771 0.000
L1.Salzburg 0.052826 0.022126 2.388 0.017
L1.Steiermark -0.016767 0.029062 -0.577 0.564
L1.Tirol 0.122423 0.023653 5.176 0.000
L1.Vorarlberg 0.071278 0.020334 3.505 0.000
L1.Wien 0.045424 0.036969 1.229 0.219
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038584 0.160221 0.181412 0.168664 0.142264 0.127911 0.065676 0.218738
Kärnten 0.038584 1.000000 0.001442 0.132289 0.026884 0.099335 0.432664 -0.049293 0.101144
Niederösterreich 0.160221 0.001442 1.000000 0.346053 0.170201 0.312859 0.128220 0.191813 0.340523
Oberösterreich 0.181412 0.132289 0.346053 1.000000 0.234456 0.341782 0.178352 0.179946 0.272468
Salzburg 0.168664 0.026884 0.170201 0.234456 1.000000 0.153441 0.137312 0.153036 0.140450
Steiermark 0.142264 0.099335 0.312859 0.341782 0.153441 1.000000 0.160221 0.148198 0.093912
Tirol 0.127911 0.432664 0.128220 0.178352 0.137312 0.160221 1.000000 0.123130 0.164089
Vorarlberg 0.065676 -0.049293 0.191813 0.179946 0.153036 0.148198 0.123130 1.000000 0.019247
Wien 0.218738 0.101144 0.340523 0.272468 0.140450 0.093912 0.164089 0.019247 1.000000